package cn.fsd.controller;

import cn.fsd.domain.Customer_address;
import cn.fsd.service.impl.Customer_addressServiceImpl;
import cn.fsd.vo.ResultBean;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/customer")
public class Customer_addressController {
    final
    Customer_addressServiceImpl addressService;

    public Customer_addressController(Customer_addressServiceImpl addressService) {
        this.addressService = addressService;
    }

    /**
     * 获得一个客户的所有地址
     *
     * @param id 客户id
     * @return 所有地址
     */
    @RequestMapping(value = "/getAddressList/{id}", method = RequestMethod.GET)
    @ApiOperation("获得一个客户的所有地址")
    public ResultBean getAddressOfCustomer(@PathVariable String id) {
        List<Customer_address> address = addressService.getAddressOfCustomer(id);
        return ResultBean.success(address);
    }

    @RequestMapping(value = "/updateAddress", method = RequestMethod.POST)
    @ApiOperation("更新地址信息")
    public ResultBean updateAddress(@RequestBody Customer_address address) {
        addressService.updateAddress(address);
        return ResultBean.success();
    }

    @RequestMapping(value = "/addAddress", method = RequestMethod.POST)
    @ApiOperation("新建地址信息")
    public ResultBean addAddress(@RequestBody Customer_address address) {
        addressService.addAddress(address);
        return ResultBean.success();
    }

    @RequestMapping(value = "/deleteAddress/{id}/{choice}", method = RequestMethod.GET)
    @ApiOperation("删除地址信息")
    public ResultBean deleteAddress(@PathVariable String id, @PathVariable Integer choice) {
        addressService.deleteAddress(id, choice);
        return ResultBean.success();
    }

    @RequestMapping(value = "/getAddress/{id}/{choice}", method = RequestMethod.GET)
    @ApiOperation("获得一个客户的第choice个地址")
    public ResultBean getAddress(@PathVariable String id, @PathVariable Integer choice) {
        Customer_address address = addressService.getAddress(id, choice);
        return ResultBean.success(address);
    }

    @RequestMapping(value = "/getAddressByIdChoice/{id}/{choice}", method = RequestMethod.GET)
    public Customer_address getAddressByIdChoice(@PathVariable("id") String id,@PathVariable("choice") Integer choice) {
        return addressService.getAddress(id, choice);
    }
}
